package de.jmda.gen.java.impl;

import java.util.LinkedList;
import java.util.List;

import de.jmda.gen.Generator;
import de.jmda.gen.impl.AbstractCompoundGenerator;
import de.jmda.gen.java.StaticBlockGenerator;
import de.jmda.gen.java.StaticFieldDeclarationsGenerator;
import de.jmda.gen.java.StaticMethodDeclarationsGenerator;
import de.jmda.gen.java.StaticPartGenerator;


public class DefaultStaticPartGenerator
    extends AbstractCompoundGenerator
    implements StaticPartGenerator
{
	private StaticFieldDeclarationsGenerator staticFieldDeclarationsGenerator;
	private StaticBlockGenerator staticBlockGenerator;
	private StaticMethodDeclarationsGenerator staticMethodDeclarationsGenerator;

	public DefaultStaticPartGenerator()
  {
	  this(null, null, null);
  }

	public DefaultStaticPartGenerator(
      StaticFieldDeclarationsGenerator staticFieldDeclarationsGenerator,
      StaticBlockGenerator staticBlockGenerator,
      StaticMethodDeclarationsGenerator staticMethodDeclarationsGenerator)
  {
	  super();

	  this.staticFieldDeclarationsGenerator = staticFieldDeclarationsGenerator;
	  this.staticBlockGenerator = staticBlockGenerator;
	  this.staticMethodDeclarationsGenerator = staticMethodDeclarationsGenerator;
	  
	  setComponentSeparator(DOUBLE_LINE_SEPARATOR);
  }

	/**
	 * @return collection of <code>Generator</code>s with the return values of the
	 *         following methods in the following order:
	 *         <ul>
	 *           <li>{@link #getStaticFieldDeclarationsGenerator()}</li>
	 *           <li>{@link #getStaticBlockGenerator()}</li>
	 *           <li>{@link #getStaticMethodDeclarationsGenerator()}</li>
	 *         </ul>
	 * 
	 * @see de.jmda.gen.CompoundGenerator#getGeneratorComponents()
	 */
	@Override
	public List<Generator> getGeneratorComponents()
	{
		List<Generator> result = new LinkedList<Generator>();

		result.add(getStaticFieldDeclarationsGenerator());
		result.add(getStaticBlockGenerator());
		result.add(getStaticMethodDeclarationsGenerator());

		return result;
	}

	@Override
	public StaticFieldDeclarationsGenerator getStaticFieldDeclarationsGenerator()
	{
		return staticFieldDeclarationsGenerator;
	}

	@Override
	public StaticBlockGenerator getStaticBlockGenerator()
	{
		if (staticBlockGenerator == null)
		{
			staticBlockGenerator = new DefaultStaticBlockGenerator();
		}

		return staticBlockGenerator;
	}

	@Override
	public StaticMethodDeclarationsGenerator getStaticMethodDeclarationsGenerator()
	{
		if (staticMethodDeclarationsGenerator == null)
		{
			staticMethodDeclarationsGenerator =
			    new DefaultStaticMethodDeclarationsGenerator();
		}

		return staticMethodDeclarationsGenerator;
	}

	public void setStaticFieldDeclarationsGenerator(
			StaticFieldDeclarationsGenerator staticFieldDeclarationsGenerator)
	{
		this.staticFieldDeclarationsGenerator = staticFieldDeclarationsGenerator;
	}

	public void setStaticBlockGenerator(StaticBlockGenerator staticBlockGenerator)
	{
		this.staticBlockGenerator = staticBlockGenerator;
	}

	public void setStaticMethodDeclarationsGenerator(
			StaticMethodDeclarationsGenerator staticMethodDeclarationsGenerator)
	{
		this.staticMethodDeclarationsGenerator = staticMethodDeclarationsGenerator;
	}
}